(() => {
    formContainer.addEventListener('submit', async(e) => {
        e.preventDefault();
        const loginId = userName.value;
        const loginPwd = userPassword.value;
        const login = await (async() => {
            try {
                const form = await fetch('https://study.duyiedu.com/api/user/login', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ loginId, loginPwd }),
                });
                const token = form.headers.get('Authorization');

                if (token) {
                    sessionStorage.setItem('token', token);
                }

                return form;
            } catch (err) {
                console.log('sd', err);
            }
        })();
        const newlogin = await login.json();

        //当反回为成功后做啥
        if (newlogin.code === 0) {
            // userName.value = '';
            // userPassword.value = '';
            window.open('./index.html', '_self');
        }
        //当返回为错误信息后做啥
        if (newlogin.code === 400) {
            userName.value = '';
            userPassword.value = '';
            window.alert(newlogin.msg);
        }
    });
})();